package org.tity.test.sql;

import java.util.ArrayList;
import java.util.List;

import org.tity.sql.sql.builder.CE;
import org.tity.sql.sql.builder.In;
import org.tity.sql.sql.builder.SE;
import org.tity.sql.sql.builder.Where;

public class CEDemo {

	public static void main(String[] args) {
		
		//构建CE，CE 继承自 ConditionExpression
		CE ce=new CE("a=?",12);
		//输出(默认以and开头) ： AND  a= 12 
		System.out.println(ce);
		
		//输出以where开头的条件表达式
		ce.startWithWhere();
		System.out.println(ce);
		
		//输出以空格开头的条件表达式
		ce.startWithSpace();
		System.out.println(ce);
		
		//增加条件
		ce.and("b=? ", 90);
		//输出   a= 12  AND b= 90 
		System.out.println(ce);
		
		//andIf内部判断是否为空，如果空则不连入
		String  c = null;
		ce.andIf("c=?",c);
		//输出   a= 12  AND b= 90 
		System.out.println(ce);
		
		
		
		//构建IN语句
		List<String> items=new ArrayList<>();
		
		items.add("001");
		items.add("A");
		items.add("B");
		items.add("112");
		
		In in=new In("x", items); 
		
		//输出  x in ( '001'   , 'A'   , 'B'   , '112'  )
		System.out.println(in);
		
		ce.and(in);
		//输出   a= 12  AND b= 90  AND x in ( '001'   , 'A'   , 'B'   , '112'  ) 
		System.out.println(ce);
		
		//构建Where，Where 继承自 ConditionExpression
		Where wh =new Where("s=?",90);
		wh.and(ce);
		//输出： WHERE  s= 90  AND (  a= 12   AND b= 90   AND x in ( '001'   , 'A'   , 'B'   , '112'  ) ) 
		System.out.println(wh);
		
	}
 
//	 public R queryMyOfficeObject(String status, String user_id) {
//	  if (ToolUtil.isEmpty(user_id)) {
//	   user_id = this.getUserId();
//	  }
////	  String sql = "select t.* from BUS_OFFICEOBJ_ACTION  t where dr='0' and t.PETITIONERUSERID='" + user_id + "'";
//	  SE se=new SE("select t.* from BUS_OFFICEOBJ_ACTION  t where dr='0' and t.PETITIONERUSERID=?",user_id);
//	  
////	  if (ToolUtil.isNotEmpty(status)) {
////	   sql = sql + " and t.status='" + status + "' ";
////	  }
//	  se=se.appendIf(" and t.status=?",status);
////	  sql = sql + "  order by t.create_time desc ";
//	  se=se.append("order by t.create_time desc");
////	  return R.SUCCESS_OPER(db.query(sql).toJsonArrayWithJsonObject());
//	  return R.SUCCESS_OPER(db.query(se.getListParameterSQL(),se.getListParameters()l).toJsonArrayWithJsonObject());
//	 }
	
}
